package com.example.moblie2021606143cwj0506;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    private TextView tvMainTitle;
    private EditText edtTxtMainInput;
    private Button btnMainIE;
    private Button btnMainCall;
    private Button btnMainMap;
    private Button btnMainCamera;
    private Intent intent;
    private  String input;
    private Uri uri;

    @Override

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }
     @Override
     public void onClick(View V){
         switch (V.getId()){
             case R.id.btn_main_IE:
                 input = edtTxtMainInput.getText().toString().trim();
                 uri = Uri.parse(input);
                 intent = new Intent(Intent.ACTION_VIEW,uri);
                 startActivity(intent);
                 break;
             case R.id.btn_main_Call:
                 input = edtTxtMainInput.getText().toString().trim();
                 uri = Uri.parse("tel:" + input);
                 intent = new Intent(Intent.ACTION_DIAL,uri);
                 startActivity(intent);
                 break;
             case R.id.btn_main_Camera:
                 intent= new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                 startActivity(intent);
                 break;
             case R.id.btn_main_Map:
                 input = edtTxtMainInput.getText().toString().trim();
                 uri = Uri.parse("geo:" + input);
                 intent = new Intent(Intent.ACTION_VIEW,uri);
                 startActivity(intent);
                 break;

         }

     }

    private void initView() {


        tvMainTitle = (TextView) findViewById(R.id.tv_main_title);
        edtTxtMainInput = (EditText) findViewById(R.id.edtTxtMainInput);
        btnMainIE = (Button) findViewById(R.id.btn_main_IE);
        btnMainCall = (Button) findViewById(R.id.btn_main_Call);
        btnMainMap = (Button) findViewById(R.id.btn_main_Map);
        btnMainCamera = (Button) findViewById(R.id.btn_main_Camera);
        btnMainIE.setOnClickListener( this);
        btnMainCall.setOnClickListener( this);
        btnMainCamera.setOnClickListener( this);
        btnMainMap.setOnClickListener( this);
    }
}